import dayjs from "dayjs";

// 将 YYYYMMDD 格式的日期转换为 M/D
export const formatDay = (day: string) => {
    const year = day.slice(0, 4);
    const month = day.slice(4, 6);
    const date = day.slice(6, 8);
    const formattedDate = new Date(`${year}-${month}-${date}`);
    return `${formattedDate.getMonth() + 1}/${formattedDate.getDate()}`;
};

// 判断是否为周末并返回六或日
export const getWeekdayText = (day: string) => {
    const year = day.slice(0, 4);
    const month = day.slice(4, 6);
    const date = day.slice(6, 8);
    const formattedDate = new Date(`${year}-${month}-${date}`);
    const dayOfWeek = formattedDate.getDay();

    if (dayOfWeek === 0) return '日'; // 周日
    if (dayOfWeek === 6) return '六'; // 周六
    return ''; // 非周末
};

// 格式话日期
export const formatData = (dateString: string) => {
    const date = dayjs(dateString, 'YYYYMMDD')
    const month = date.month() + 1
    const day = date.date()
    return `${month}/${day}`
}